#!/bin/bash
clear

TEXT='\033[30;107;2m'
INFO='\033[97;44m'
WARNING='\033[97;43m'
ERROR='\033[97;41m'
SUCCESS='\033[97;42m'
GREEN='\033[92m'
YELLOW='\033[93m'
RESET='\033[0m'

if [ "${EUID}" -ne 0 ]; then
  echo -e "${ERROR} RALAT ${RESET}${TEXT} Anda tiada kebenaran untuk menjalankan skrip ini! ${RESET}"; exit 1
fi

alamat_ip=$(wget -qO- ipv4.icanhazip.com)
alamat_hos=$(cat /etc/environment | grep 'DOMAIN' | cut -d '=' -f 2 | head -n 1)
nama_pengguna=$(</dev/urandom tr -dc A-Z | head -c5)
egrep "^$nama_pengguna" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
  echo -e "${ERROR} RALAT ${RESET}${TEXT} Nama pengguna sudah wujud! ${RESET}"; exit 1
fi
kata_laluan=$(</dev/urandom tr -dc 0-9 | head -c5)
tempoh_aktif=1
tarikh_luput=$(date -d "$tempoh_aktif days" +"%F")

useradd $nama_pengguna
usermod -s /bin/false $nama_pengguna
usermod -e $tarikh_luput $nama_pengguna
echo -e "$kata_laluan\n$kata_laluan" | passwd $nama_pengguna &>/dev/null

clear
echo
echo -e "${TEXT} ========================================================== ${RESET}"
echo -e "${TEXT} DROPBEAR & OPENVPN - AKAUN PERCUBAAN                       ${RESET}"
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo
echo -e "${YELLOW}     Alamat IP:${PLAIN} ${GREEN}$alamat_ip${PLAIN}"
echo -e "${YELLOW}   Nama domain:${PLAIN} ${GREEN}$alamat_hos${PLAIN}"
echo -e "${YELLOW} Nama pengguna:${PLAIN} ${GREEN}$nama_pengguna${PLAIN}"
echo -e "${YELLOW}   Kata laluan:${PLAIN} ${GREEN}$kata_laluan${PLAIN}"
echo -e "${YELLOW}  Tempoh aktif:${PLAIN} ${GREEN}$tempoh_aktif hari${PLAIN}"
echo -e "${YELLOW}  Tarikh luput:${PLAIN} ${GREEN}$tarikh_luput${PLAIN}"
echo -e " ---------------------------------------------------------- "
echo -e "${YELLOW}OpenVPN [TCP]:${RESET} ${GREEN} https://$alamat_hos/client-tcp.ovpn${RESET}"
echo -e "${YELLOW}OpenVPN [UDP]:${RESET} ${GREEN} https://$alamat_hos/client-udp.ovpn${RESET}"
echo -e "${YELLOW}OpenVPN [TLS]:${RESET} ${GREEN} https://$alamat_hos/client-tls.ovpn${RESET}"
echo
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo -e "${TEXT} Dicipta oleh Doctype, Dikuasakan oleh Cybertize.           ${RESET}"
echo -e "${TEXT} ========================================================== ${RESET}"
echo